var prefix = "/jzweb/jazSysProject";
layui.use(['form', 'upload'], function(){
	var form = layui.form;
	var layer = layui.layer;
	var upload = layui.upload;
	var loading;

	//拖拽上传
	upload.render({
		elem: '#drag'
		,url: '/common/sysFile/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
		// ,field:'picture'
		,before: function(){
			loading = layer.load({
				type:3,
				content:'加载中...',
			});//在post之前定义loading
		}
		,done: function(res){
			layer.close(loading);
			if( res.code == 0 ){
				layer.msg('上传成功');
				layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.data);
				$("input[name='icon']").val(res.data)
			}else{
				layer.msg('上传失败,请检查');
			}
		}
	});

	form.verify({
		name: function(value){
			if( !value ){
				return '请输入您的项目名称';
			}
		},
		picture: function (value){
			if(!value){
				return '请上传你的项目图标';
			}
		}
	})

	//提交事件
	form.on('submit(submit)', function(data){

		$.ajax({
			url : prefix+"/save",
			type : "post",
			data : data.field,
			success : function(r) {
				if (r.code==0) {

					parent.layer.msg("操作成功");
					parent.load();
					var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
					parent.layer.close(index);

				}else{
					layer.msg(r.msg);
				}
			}
		});

		return false;
	});

});